package com.sample.kokou;

import android.widget.TextView;
import java.sql.SQLException;

import android.view.View;

import android.os.Bundle;

import com.j256.ormlite.android.apptools.OrmLiteBaseActivityGroup;
import com.j256.ormlite.dao.Dao;

public class NewPersonActivity extends OrmLiteBaseActivityGroup<SampleDBHelper> {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO 自動生成されたメソッド・スタブ
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_person);
    }

    public void onCancel(View v) {
        finish();
    }

    public void onOk(View v) {
        TextView name_view = GenericUtil.getView(this, R.id.nameText);
        String name = name_view.getText().toString();
        TextView age_view = GenericUtil.getView(this, R.id.ageText);
        int age = Integer.parseInt(age_view.getText().toString());
        try {
            Dao<Person, Integer> dao = getHelper().getDao(Person.class);
            dao.create(new Person(name, age));
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        finish();
    }
}
